jQuery(document).ready(function($) {
	var uploader = 'swfupload/uploadify_cn.swf';
	var script = '/action/master/ArticleImageUpload';
	var cancelImg = 'swfupload/cancel.png';
	var folder = '/upload';
	
	
	$('#images_file').uploadify({
		'uploader'  : uploader,
		'script'    : script,
		'cancelImg' : cancelImg,
		'folder'    : folder,
		'auto'      : true,
		'multi'     : true,
		'fileExt'   : '*.jpg;*.gif;*.png;*.bmp',
		'fileDesc'  : '请选择图片文件 (.JPG, .GIF, .PNG, .BMP)',
		'queueID'        : 'custom-queue',
		'buttonText' : "选择上传图片",
		'removeCompleted' : true,
		'onComplete':function(e,queueId,fileObj,response,data){
			var obj = $.parseJSON(response);
			if (obj.success){
				tinyMCE.execCommand("mceReplaceContent",false,"<img src=\""+obj.filepath+"\">");
				$(".attachment").show();
				var templateTr = $("#photo-preview-tpl").children("li").clone().show();
				templateTr.find("img").attr("src",obj.filepath);
				templateTr.find("a").attr("href",obj.fileid);
				templateTr.find("a").click(delphotoClickHandler).easyconfirm({locale: { title: '操作确认', button: ['取消','是的，确定删除']}});
				templateTr.find("input").val(obj.filepath);
				$('#photo-preview').append(templateTr);
			}else{
				 $('#status-message').append("<li>"+obj.message+"</li>");
			}
		}

	});
	
	
	
	$('#attachment_file').uploadify({
		'uploader'  : uploader,
		'script'    : "/action/master/ArticleFileUpload",
		'cancelImg' : cancelImg,
		'folder'    : folder,
		'auto'      : true,
		'multi'     : true,
		'fileExt'   : '*.*',
		'fileDesc'  : '请选择文件',
		'queueID'        : 'custom-queue',
		'buttonText' : "选择上传附件",
		'removeCompleted' : true,
		'onComplete':function(e,queueId,fileObj,response,data){
			//console.log(response);
			var obj = $.parseJSON(response);
			if (obj.success){
				//alert("OK");
				$(".attachment").show();
				var templateTr = $("#attachment-preview-tpl").children("li").clone(true).show();
				templateTr.find("a").attr("href",obj.fileid);
				templateTr.find("b").text(obj.originalnames);
				$('#attachment-preview').append(templateTr);

			}else{
				 $('#status-message').append("<li>"+obj.message+"</li>");
			}
		}

	});
	
	$('#upload_image').uploadify({
		'uploader'  : uploader,
		'script'    : script,
		'cancelImg' : cancelImg,
		'folder'    : folder,
		'auto'      : true,
		'multi'     : true,
		'fileExt'   : '*.jpg;*.gif;*.png;*.bmp',
		'fileDesc'  : '请选择图片文件 (.JPG, .GIF, .PNG, .BMP)',
		'queueID'        : 'custom-queue',
		'removeCompleted' : true,
		'onSelectOnce'   : function(event,data) {
		  $('#status-message').text(data.filesSelected + ' 个文件加入上传队列.');
		},
	   'onAllComplete'  : function(event,data) {
		  $('#status-message').text(data.filesUploaded + ' 个文件上传成功, ' + data.errors + ' 失败.');
		}
	});
	
	
});
